package subject_set.top101;

import java.util.ArrayList;

/**
 * @author haomin
 * @date 2022/11/01 20:36
 **/
public class BM27 {
    public class Solution {
        ArrayList<ArrayList<Integer>> res = new ArrayList<>();
        public ArrayList<ArrayList<Integer> > Print(TreeNode pRoot) {
            preOrder(pRoot, 0);
            return res;
        }
        private void preOrder(TreeNode cur, int k){
            if(cur == null) return;
            if(res.size() <= k)
                res.add(new ArrayList<>());
            if(k % 2 == 0) res.get(k).add(cur.val);
            else res.get(k).add(0, cur.val);

            preOrder(cur.left, k+1);
            preOrder(cur.right, k+1);
        }
    }
}